package com.wowangz.cms.dailyoperation.note.service;

import java.rmi.server.ServerCloneException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.wowangz.cms.dailyoperation.note.entity.DemandNote;
import com.wowangz.cms.dailyoperation.note.entity.DemandNoteClazz;
import com.wowangz.cms.syscore.exception.ServiceException;
import com.wowangz.cms.syscore.service.BaseService;

public class DemandNoteService extends BaseService{

	/**
	 * 保存
	 * @param demandNote
	 * @return
	 */
	public int insert(DemandNote demandNote)throws ServiceException{
		return this.getSqlSession().insert("demandNote.insert", demandNote);
	}
	
	/**
	 * 查询单挑记录
	 * @param map
	 * @return
	 */
	public DemandNote findOne(Map<String, Object> map)throws ServiceException{
		return this.getSqlSession().selectOne("demandNote.findOne", map);
	}
	
	/**
	 * 修改
	 * @param demandNote
	 */
	public void update(DemandNote demandNote) throws ServiceException{
		this.getSqlSession().update("demandNote.update", demandNote);
	}

	/**
	 * 查询分页
	 * @param map
	 * @return
	 * @throws ServerCloneException
	 */
	public List<Map<String, Object>> findList(Map<String, Object> map) throws ServiceException {
		return this.getSqlSession().selectList("demandNote.queryPageByParams", map);
	}

	
	public List<DemandNoteClazz> findResultList(Map<String, Object> paramMap) throws ServiceException{
		List<Map<String, Object>> mapList = findList(paramMap);
		List<DemandNoteClazz> demandNoteClazzs = new ArrayList<DemandNoteClazz>();
		for (Map<String, Object> map : mapList) {
			demandNoteClazzs.add(getDemandNoteClazz(map));
			
		}
		return demandNoteClazzs;
	}
	
	
	private DemandNoteClazz getDemandNoteClazz(Map<String, Object> map)throws ServiceException{
		return new DemandNoteClazz(map);
	}
	
	/**
	 * 分页查询总条数
	 * 
	 * @param map
	 * @return
	 */
	public long findResultCount(Map<String, Object> map) throws ServiceException {
		List<Object> list = this.getSqlSession().selectList("demandNote.queryStoreCount", map);
		return list.size();
	}
}
